package com.example.demo.timu.chanshu;

import com.example.demo.timu.tianyiyun.Tiku;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Map;

@Repository
public interface TikusRepository extends JpaRepository<Tikus, Long> {

    @Query(value = "SELECT * FROM tikus where question like ?1 limit 5", nativeQuery = true)
    List<Tikus> getTikus(String obj);

    @Query(value = "SELECT question,answer,CONCAT_WS(';',a,b,c,d,e,f) as choose FROM tikus ", nativeQuery = true)
    List<Map<String,String>> getAllTikus();

    @Transactional
    @Modifying
    @Query(value = "truncate table tikus", nativeQuery = true)
    void truncateTable();
}